package com.qsboss.demo.aop;

import com.qsboss.demo.mapper.TbSysLogMapper;
import com.qsboss.demo.pojo.TbSysLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author 军哥
 * @version 1.0
 * @description: AOP
 * @date 2023/10/29 17:03
 */

public class LoggingAspect {

    @Autowired
    TbSysLogMapper tbSysLogMapper;


    /***
     * @description 前置通知
     * @return void
     * @author 军哥
     * @date 2023/10/29 17:22
     */
    public void before(JoinPoint jp) {
        System.out.println("====================aop====================");
        System.out.println("1...前置通知,切入类"+jp.getTarget().getClass());
        System.out.println("1...前置通知,切入方法"+jp.getSignature().getName());
        System.out.println("1...前置通知,参数："+ Arrays.toString(jp.getArgs()));

        TbSysLog tbSysLog = new TbSysLog();
        tbSysLog.setLogName(jp.getSignature().getName());
        tbSysLog.setLogDesc(Arrays.toString(jp.getArgs()));

        tbSysLogMapper.addSysLog(tbSysLog);
    }
}
